<template>
	<view class="page-container">
		<back :showBackText="false" customClass="bg-gradual-blue text-white" title="学习资料"></back>
		
		<view class="content-container" v-if="isLoad">
			<scroll-view scroll-y="true" class="scroll-area">
				<!-- 空状态显示 -->
				<empty v-if="dataList.length == 0" info="暂时还没有资料" :showAd="false"></empty>
				
				<!-- 资料列表 -->
				<view class="material-list" v-else>
					<view class="material-card" v-for="(item, index) in dataList" :key="index" :data-id="item.id" @tap="itemTap">
						<!-- 资料标题区域 -->
						<view class="card-header">
							<view class="title-area">
								<text class="cuIcon-file text-blue"></text>
								<text class="title-text">{{item.name}}</text>
							</view>
							<view class="hot-badge">
							<text class="cuIcon-hotfill text-red"></text>
							<text class="hot-count">{{item.hot}}</text>
						</view>
						</view>
						
						<!-- 资料描述区域 -->
						<view class="card-content">
							<text class="description">{{item.desc}}</text>
						</view>
						
						<!-- 资料底部区域 -->
						<view class="card-footer">
							<view class="price-tag">
								<text class="price-icon cuIcon-moneybag text-yellow"></text>
								<text class="price-value">{{item.price}}</text>
								<text class="price-label">积分</text>
							</view>
							<view class="action-button">
								<text class="cuIcon-attention"></text>
								<text>查看详情</text>
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
		
		<!-- 底部分享按钮 -->
		<view class="float-action-container" v-if="isLoad && !appIsAudit">
			<view class="share-button" @tap="shareTap">
				<text class="cuIcon-add"></text>
				<text>分享资料</text>
			</view>
		</view>
	</view>
</template>

<script>
	let that = null;
	let app = getApp();
	export default {
		data() {
			return {
				id: 0,
				isLoad: false,
				appIsAudit: app.globalData.checkAppIsAudit(),
				dataList: []
			};
		},
		onLoad(options) {
			that = this;
			that.id = options.id;
			that.getList();
		},
		methods: {
			itemTap(options) {
				console.log(options)
				let id = options.currentTarget.dataset.id;
				let url = `/pages/practice/material/detail?id=${id}`;
				uni.navigateTo({
					url: url
				});
			},
			shareTap(options) {
				let url = `/pages/practice/material/share?id=${that.id}`;
				uni.navigateTo({
					url: url
				});
			},
			getList() {
				if(that.appIsAudit){
					that.isLoad = true;
					return;
				}
				app.globalData.service.getMaterialList(that.id).then(res => {
						that.setData({
							isLoad: true,
							dataList: res.data
						});
					})
					.catch(function(a) {
						app.showToast('获取资料失败');
					});
			},
		}
	};
</script>
<style>
	@import './list.css';
</style>
<style lang="scss" scoped>
	/* #ifndef H5 */
	page {
		height: 100%;
		background-color: #f5f7fa;
	}
	/* #endif */
	
	.page-container {
		display: flex;
		flex-direction: column;
		height: 100%;
	}
	
	.content-container {
		flex: 1;
		padding: 20rpx;
	}
	
	.scroll-area {
		height: calc(100vh - 200rpx);
	}
	
	.material-list {
		padding-bottom: 120rpx;
	}
	
	.material-card {
		background-color: #ffffff;
		border-radius: 16rpx;
		box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.05);
		margin-bottom: 24rpx;
		padding: 24rpx;
		transition: all 0.3s ease;
		
		&:active {
			transform: scale(0.98);
			opacity: 0.9;
		}
	}
	
	.card-header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 16rpx;
		
		.title-area {
			display: flex;
			align-items: center;
			
			.cuIcon-file {
				font-size: 36rpx;
				margin-right: 12rpx;
			}
			
			.title-text {
				font-size: 32rpx;
				font-weight: bold;
				color: #333333;
			}
		}
		
		.hot-badge {
			background: linear-gradient(135deg, #ff6b6b, #ff8e8e);
			border-radius: 30rpx;
			padding: 6rpx 16rpx;
			display: flex;
			align-items: center;
			
			.cuIcon-hotfill {
				margin-right: 4rpx;
			}
			
			.hot-count {
				color: #ffffff;
				font-size: 24rpx;
				font-weight: bold;
			}
		}
	}
	
	.card-content {
		padding: 16rpx 0;
		
		.description {
			font-size: 28rpx;
			color: #666666;
			line-height: 1.5;
			display: -webkit-box;
			-webkit-line-clamp: 3;
			-webkit-box-orient: vertical;
			overflow: hidden;
			text-overflow: ellipsis;
		}
	}
	
	.card-footer {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 16rpx;
		padding-top: 16rpx;
		border-top: 1px solid #f0f0f0;
		
		.price-tag {
			display: flex;
			align-items: center;
			
			.price-icon {
				font-size: 32rpx;
				margin-right: 8rpx;
			}
			
			.price-value {
				font-size: 32rpx;
				font-weight: bold;
				color: #ff9500;
				margin-right: 4rpx;
			}
			
			.price-label {
				font-size: 24rpx;
				color: #999999;
			}
		}
		
		.action-button {
			background: linear-gradient(135deg, #0081ff, #1cbbb4);
			border-radius: 30rpx;
			padding: 12rpx 24rpx;
			display: flex;
			align-items: center;
			
			text {
				color: #ffffff;
				font-size: 26rpx;
			}
			
			.cuIcon-attention {
				margin-right: 8rpx;
				font-size: 28rpx;
			}
		}
	}
	
	.float-action-container {
		position: fixed;
		bottom: 30rpx;
		right: 30rpx;
		z-index: 99;
		
		.share-button {
			background: linear-gradient(135deg, #0081ff, #1cbbb4);
			border-radius: 50rpx;
			box-shadow: 0 6rpx 20rpx rgba(0, 129, 255, 0.3);
			padding: 16rpx 32rpx;
			display: flex;
			align-items: center;
			
			text {
				color: #ffffff;
			}
			
			.cuIcon-add {
				font-size: 32rpx;
				margin-right: 8rpx;
			}
		}
	}
</style>
